﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Extension;

[AddComponentMenu("UI/SubjectiveImage")]
public class SubjectiveImage : Image
{
    [SerializeField]
    ControlSubject m_subject = new ControlSubject(false, typeof(string));
    public ControlSubject subject { get { return m_subject; } }
    protected override void Start()
    {
        base.Start();
        if (subject.hasValidResource<UnityEngine.Sprite>())
            sprite = subject.resource as UnityEngine.Sprite;
    }
    
    void LateUpdate()
    {
        if (subject.hasUpdate)
        {
            if (subject.hasValidResource<UnityEngine.Sprite>())
                sprite = subject.resource as UnityEngine.Sprite;
        }
    }

#if UNITY_EDITOR

    protected override void OnValidate()
    {
        base.OnValidate();
        if (subject.hasValidResource<UnityEngine.Sprite>())
            sprite = subject.resource as UnityEngine.Sprite;
    }
#endif
}
